<?php

namespace app\admin\model\xilujob;

use app\admin\model\User;
use think\Exception;
use think\Model;
use traits\model\SoftDelete;

class Member extends Model
{

    use SoftDelete;

    // 表名
    protected $name = 'xilujob_member';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'actiontime_text',
        'source_text'
    ];

    const SOURCE_REGISTER = '0'; //注册
    const SOURCE_BACKEND = '1'; //后台添加
    //const SOURCE_BACKEND_ONLY_RESUME = '2'; //后台添加简历, 用户数据无用
    //const SOURCE_SHARE_LOGIN = '3'; //简历、自助登记用户
    

    
    public function getSourceList()
    {
        return ['0' => __('Source 0'), '1' => __('Source 1')];
    }


    public function getActiontimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['actiontime']) ? $data['actiontime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getSourceTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['source']) ? $data['source'] : '');
        $list = $this->getSourceList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function user() {
        return $this->belongsTo(User::class, 'user_id','id',[],'INNER')->setEagerlyType(0);
    }
    public function xilujobuser() {
        return $this->belongsTo(XilujobUser::class, 'user_id','user_id',[],'INNER')->setEagerlyType(0);
    }

}
